<?php
// +----------------------------------------------------------------------
// | HisiPHP框架[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2021 http://www.hisiphp.com
// +----------------------------------------------------------------------
// | HisiPHP承诺基础框架永久免费开源，您可用于学习和商用，但必须保留软件版权信息。
// +----------------------------------------------------------------------
// | Author: 橘子俊 <364666827@qq.com>，开发者QQ群：50304283
// +----------------------------------------------------------------------

namespace app\system\admin;

use app\common\model\Resource as ResourceModel;


/**
 * 后台用户、角色控制器
 * @package app\system\admin
 */
class Resource extends Admin
{
    protected $hisiTable = 'Resource';
    protected $hisiModel = 'Resource';

    /**
     * 用户管理
     * @author 橘子俊 <364666827@qq.com>
     * @return mixed
     */
    public function index($q = '')
    {
        if ($this->request->isAjax()) {
            $where      = [];
            $page       = $this->request->param('page/d', 1);
            $limit      = $this->request->param('limit/d', 15);
            $name   = $this->request->param('name/s');
            if ($name) {
                $where[] = ['name', 'like', "%{$name}%"];
            }

            $rs = ResourceModel::where($where)->page($page)->limit($limit)->select();
            $count = ResourceModel::where($where)->count('id');
            return $this->layuiJson($rs , $count);
        }
        return $this->fetch();
    }

    public function image(){
        if ($this->request->isAjax()) {
            $id = $this->request->get('id');
            if ($this->request->get('id')){
                $data = ResourceModel::where('id',$id)->field('url src,name alt,id pid')->select();
                foreach ($data as $key => $value) {
                    $data[$key]['src'] = config('aly_config.oss_upload_url').$value['src'];
                    $data[$key]['alt'] = $value['alt'];
                    $data[$key]['pid'] = $value['pid'];
                }
                return json(['title'=>'','id'=>'','start'=>'','data'=>$data]);
            }
        } else {
            return $this->fetch();
        }
    }
}
